/**
 * 
 */
package persistence;

import jpa_objects.Branch;
import jpa_objects.Business;
import jpa_objects.Business_type;
import jpa_objects.City;
import jpa_objects.Comment;
import jpa_objects.Discount;
import jpa_objects.Event;
import jpa_objects.Event_report;
import jpa_objects.Event_suggestion;
import jpa_objects.Feedback;
import jpa_objects.Instructor;
import jpa_objects.Instructor_type;
import jpa_objects.Message;
import jpa_objects.Notification;
import jpa_objects.Player;
import jpa_objects.Review;
import jpa_objects.Sport;
import jpa_objects.Sport_calification;
import jpa_objects.User;
import jpa_objects.User_report;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;



/**
 * @author Alejandro Casas
 *
 */
public class DBConnector {
	
	public static SessionFactory sf;
	private static AnnotationConfiguration conf;

	private static void setup()
	{
		conf= new AnnotationConfiguration();
		conf.addAnnotatedClass(Branch.class);
		conf.addAnnotatedClass(Business_type.class);
		conf.addAnnotatedClass(Business.class);
		conf.addAnnotatedClass(City.class);
		conf.addAnnotatedClass(Comment.class);
		conf.addAnnotatedClass(Discount.class);
		conf.addAnnotatedClass(Event_report.class);
		conf.addAnnotatedClass(Event_suggestion.class);
		conf.addAnnotatedClass(Event.class);
		conf.addAnnotatedClass(Feedback.class);
		conf.addAnnotatedClass(Instructor_type.class);
		conf.addAnnotatedClass(Instructor.class);
		conf.addAnnotatedClass(Message.class);
		conf.addAnnotatedClass(Notification.class);
		conf.addAnnotatedClass(Player.class);
		conf.addAnnotatedClass(Review.class);
		conf.addAnnotatedClass(Sport_calification.class);
		conf.addAnnotatedClass(Sport.class);
		conf.addAnnotatedClass(User_report.class);
		conf.addAnnotatedClass(User.class);
		conf.configure();

		//new SchemaExport(conf).create(true, true);
		sf= conf.buildSessionFactory();
		
	}
	
	public static org.hibernate.classic.Session openSession()
	{
		if(conf == null)
		{
			setup();
		}
		sf= conf.buildSessionFactory();
		return sf.getCurrentSession();
	}
}
